package kr.hkit.androidcomplete01.chapter08;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

public class MoveCircle extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new MyView(this));
		
	}
	
	class MyView extends View{
		float mX;
		float mY;
		int mColor;
		Paint paint;
		public MyView(Context context) {
			super(context);
			mX = 100;
			mY = 100;
			mColor = Color.BLUE;
			paint = new Paint(paint.ANTI_ALIAS_FLAG);
			paint.setColor(mColor);
		}
		
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
			canvas.drawCircle(mX, mY, 16, paint);
		}
		
		
		@Override
		public boolean onTouchEvent(MotionEvent event) {
			super.onTouchEvent(event);
			if(event.getAction()==MotionEvent.ACTION_DOWN){
				mX = event.getX();
				mY = event.getY();
				invalidate();//내부적으로 호출
				return true;
			}
			return false;
		}
		
	}
}
